
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <getopt.h>

#include <sys/socket.h>
#include <sys/time.h>

#include <arpa/inet.h>

#define IP "192.168.248.130"
#define PORT 8000
#define BUF "a\r\n"

int connect_tcpserver(const char *ip, unsigned short port)
{

	int connfd = socket(AF_INET, SOCK_STREAM, 0);

	struct sockaddr_in tcpserver_addr;
	memset(&tcpserver_addr, 0, sizeof(struct sockaddr_in));

	tcpserver_addr.sin_family = AF_INET;
	tcpserver_addr.sin_addr.s_addr = inet_addr(ip);
	tcpserver_addr.sin_port = htons(port);

	int ret = connect(connfd, (struct sockaddr *)&tcpserver_addr, sizeof(struct sockaddr_in));
	if (ret)
	{
		perror("connect");
		return -1;
	}

	return connfd;
}

int main()
{
    
    int connfd = connect_tcpserver(IP, PORT);

    send(connfd, BUF, strlen(BUF), 0);

    char buffer[128] = {0};
    int count = recv(connfd, buffer, 128, 0);
    printf("buffer: %.*s\n", count , buffer);

    getchar();
}